<template>
  <lay-container fluid="true" style="padding: 10px" class="workbench">
    <lay-row space="10">
      <lay-col md="24">
        <lay-card>
          <lay-row space="10" class="tab_item">
            <lay-col md="20">
              <lay-tab
                type="brief"
                v-model="tabs"
                class="tabs"
                @change="tabChange"
                :key="itemKey"
                ref="layTab"
              >
                <lay-tab-item
                  :title="'待认领(' + tabItem.unclaimsCount + ')'"
                  id="1"
                  v-if="httpUrls.includes('/Checkmsg/GetUnclaims')"
                >
                </lay-tab-item>
                <lay-tab-item
                  :title="`5天以上未认领(${tabItem.unclaims5Count})`"
                  id="2"
                  v-if="httpUrls.includes('/Checkmsg/GetUnclaims')"
                >
                </lay-tab-item>
                <lay-tab-item
                  :title="`15天以上未认领(${tabItem.unclaims15Count})`"
                  id="3"
                  v-if="httpUrls.includes('/Checkmsg/GetUnclaims')"
                >
                </lay-tab-item>
                <lay-tab-item
                  :title="`送审中(${tabItem.submittingCount})`"
                  id="4"
                  v-if="httpUrls.includes('/Checkmsg/GetSubmitting')"
                >
                </lay-tab-item>
                <lay-tab-item
                  :title="`送审超5天(${tabItem.submitting5Count})`"
                  id="45"
                  v-if="httpUrls.includes('/Checkmsg/GetSubmitting')"
                >
                </lay-tab-item>
                <lay-tab-item
                  :title="`送审超10天(${tabItem.submitting10Count})`"
                  id="410"
                  v-if="httpUrls.includes('/Checkmsg/GetSubmitting')"
                >
                </lay-tab-item>

                <lay-tab-item
                  :title="`待审核(${tabItem.checkPendingCount})`"
                  id="5"
                  v-if="httpUrls.includes('/Checkmsg/GetCheckPending')"
                >
                </lay-tab-item>
                <lay-tab-item
                  :title="`已审核(${tabItem.examineCount})`"
                  id="6"
                  v-if="httpUrls.includes('/Checkmsg/GetExamine')"
                >
                </lay-tab-item>
                <lay-tab-item
                  :title="`已签发(${tabItem.signissueCount})`"
                  id="7"
                  v-if="httpUrls.includes('/Checkmsg/GetSignissue')"
                >
                </lay-tab-item>
                <lay-tab-item
                  :title="`已归档(${tabItem.filedCount})`"
                  id="8"
                  v-if="httpUrls.includes('/Checkmsg/GetFiledlist')"
                >
                </lay-tab-item>
              </lay-tab>
            </lay-col>
            <lay-col md="3" mdOffset="1" class="btn_alter">
              <input
                type="file"
                id="fileUpload"
                ref="fileUploads"
                style="display: none"
                @change="handleImageUpload"
              />
              <lay-button
                v-if="
                  tabs == '1' ||
                  tabs == '2' ||
                  (tabs == '3' && httpUrls.includes('/Checkmsg/CheckPointUpload'))
                "
                class="btn"
                type="primary"
                size="sm"
                value="上传文件"
                @click="clickFile"
                >上传文件</lay-button
              >

              <lay-button
                class="btn"
                type="primary"
                size="sm"
                v-if="
                  tabs == '1' ||
                  tabs == '2' ||
                  (tabs == '3' && httpUrls.includes('/Checkmsg/DelUnclaims'))
                "
                @click="allShenghe('del')"
              >
                移除
              </lay-button>
              <lay-button
                class="btn"
                type="primary"
                size="sm"
                v-if="tabs == '4' && httpUrls.includes('/Checkmsg/DoCheckPending')"
                @click="allShenghe('dai')"
              >
                批量进入待审核
              </lay-button>
              <lay-button
                class="btn"
                type="primary"
                size="sm"
                v-if="tabs == '4' && httpUrls.includes('/Checkmsg/SubmittingBack')"
                @click="allShenghe('th')"
              >
                批量退回
              </lay-button>
              <lay-button
                class="btn"
                type="primary"
                size="sm"
                @click="allShenghe('shenghe')"
                v-if="tabs == '5' && httpUrls.includes('/Checkmsg/DoExamine')"
              >
                批量审核
              </lay-button>
              <lay-button
                class="btn"
                type="primary"
                size="sm"
                @click="allShenghe('dshpl')"
                v-if="tabs == '5' && httpUrls.includes('/Checkmsg/CheckPendingBack')"
              >
                批量退回
              </lay-button>

              <lay-button
                class="btn"
                type="primary"
                size="sm"
                v-if="tabs == '6' && httpUrls.includes('/Checkmsg/DoSignissue')"
                @click="allShenghe('qianfa')"
              >
                批量签发
              </lay-button>

              <lay-button
                class="btn"
                type="primary"
                size="sm"
                v-if="tabs == '6'  && httpUrls.includes('/Checkmsg/ExamineBack')"
                @click="allShenghe('qftu')"
              >
                批量退回
              </lay-button>

              <lay-button
                class="btn"
                type="primary"
                size="sm"
                v-if="tabs == '7' && httpUrls.includes('/Checkmsg/DoFile')"
                @click="allShenghe('guidan')"
              >
                批量归档
              </lay-button>

              <lay-button
                class="btn"
                type="primary"
                size="sm"
                v-if="tabs == '7'  && httpUrls.includes('/Checkmsg/SignissueBack')"
                @click="allShenghe('plgdtu')"
              >
                批量退回
              </lay-button>
            </lay-col>
          </lay-row>

          <mearchMsg class="msg_val" @search="getSearch" :tabs="tabs"/>

          <lay-table
            id="detectionId"
            v-model:selected-keys="selectedKeys"
            :columns="getColumns(columns, Number(tabs))"
            :dataSource="dataSource"
            :checkbox="checkbox"
            :default-toolbar="['filter']"
            :cell-style="cellStyle"
          >
            <template v-slot:deviceName="{ data }">
              <lay-tooltip  trigger="click" :content="data.deviceName" >
                <div style=" text-overflow:ellipsis; white-space:nowrap; overflow:hidden; ">
                  {{data.deviceName}}
                </div>
              </lay-tooltip>
            </template>

            <template v-slot:status="{ data }">
              <lay-tag type="primary" v-if="data.status == 0">待认领</lay-tag>
              <lay-tag type="normal" v-if="data.status == 1">送审中</lay-tag>
              <lay-tag type="normal" v-if="data.status == 2">待审核</lay-tag>
              <lay-tag type="normal" v-if="data.status == 3">已审核</lay-tag>
              <lay-tag type="normal" v-if="data.status == 4">已签发</lay-tag>
              <lay-tag type="normal" v-if="data.status == 5">已归档</lay-tag>
            </template>

            <template v-slot:no1>
              <div>
                委托编号
                <lay-icon @click="headerPx({ordercolumnname: 'entrustmentNo', isascending: true})" type="layui-icon-up"></lay-icon>
                <lay-icon @click="headerPx({ordercolumnname: 'entrustmentNo', isascending: false})" type="layui-icon-down"></lay-icon>
              </div>
            </template>
            <template v-slot:no2>
              <div>
                样品编号
                <lay-icon @click="headerPx({ordercolumnname: 'sampleNo', isascending: true})" type="layui-icon-up"></lay-icon>
                <lay-icon @click="headerPx({ordercolumnname: 'sampleNo', isascending: false})" type="layui-icon-down"></lay-icon>
              </div>
            </template>
            <template v-slot:no3>
              <div>
                报告编号
                <lay-icon @click="headerPx({ordercolumnname: 'reportNo', isascending: true})" type="layui-icon-up"></lay-icon>
                <lay-icon @click="headerPx({ordercolumnname: 'reportNo', isascending: false})" type="layui-icon-down"></lay-icon>
              </div>
            </template>
            <template v-slot:no4>
              <div>
                委托日期
                <lay-icon @click="headerPx({ordercolumnname: 'entrustmentDate', isascending: true})" type="layui-icon-up"></lay-icon>
                <lay-icon @click="headerPx({ordercolumnname: 'entrustmentDate', isascending: false})" type="layui-icon-down"></lay-icon>
              </div>
            </template>

            <template v-slot:testItems="{ data }">
              <div>
                <div v-if="data.testItems.length">{{ data.testItems }}</div>
                <div v-else class="alter_text" @click="addXmName(data)">
                  <div class="red">匹配失败</div>
                  <div class="text">手动添加</div>
                </div>
              </div>
            </template>
            <template
              v-slot:alter="{ data }"
              v-if="tabs == '1' || tabs == '2' || tabs == '3'"
            >
              <lay-tag
                v-if="httpUrls.includes('/Checkmsg/DoClaim')"
                type="primary"
                @click="claimTag(data)"
                >认领</lay-tag
              >
            </template>
          </lay-table>

          <lay-page
            v-model="current"
            v-model:limit="limit"
            :pages="pages"
            :total="total"
            :show-count="true"
            :show-limit="true"
            :showSkip="true"
            :show-page="true"
            @change="changePage"
          ></lay-page>
        </lay-card>
      </lay-col>
    </lay-row>

    <layers ref="layers" @updata="getSwith()"></layers>

    <lay-layer :btn="editBtn" title="手动匹配项目" v-model="alterVisible">
      <div class="sdppxm">
        <lay-select v-model="selectVal" placeholder="选择匹配项目" :show-search="true">
          <lay-select-option
            v-for="(item, index) in selectList"
            :key="index"
            :value="item.testItemId"
            :label="item.testItemName"
          >
          </lay-select-option>
        </lay-select>
      </div>
    </lay-layer>

    <!-- 退回到处理状态,0待认领，1送审中，2待审核 3已审核-->
    <lay-layer :btn="tuiBtn" title="指定回退位置" v-model="showTuiLayu">
      <div class="sdppxm">
        <lay-select v-model="tuiString" placeholder="选择回退状态" :show-search="true">
          <lay-select-option
            value="0"
            label="待认领"
          >
          </lay-select-option>
          <lay-select-option
            value="1"
            label="送审中"
          >
          </lay-select-option>
          <lay-select-option
            value="2"
            label="待审核"
          >
          </lay-select-option>
          <lay-select-option
            v-if="tabs == '7'"
            value="3"
            label="已审核"
          >
          </lay-select-option>
        </lay-select>
      </div>
    </lay-layer>
  </lay-container>
</template>
<script lang="ts">
import { isTemplateElement } from "@babel/types";
import {
  defineComponent,
  ref,
  onMounted,
  reactive,
  toRefs,
  nextTick,
  onUnmounted,
} from "vue";
import mearchMsg from "./component/search.vue";
import layers from "./component/layer.vue";
import {
  DelUnclaims,
  GetUnclaims,
  DoCheckPending,
  GetDeviceInfos,
  ObjectStatusCountSta,
  GetSubmitting,
  GetCheckPending,
  GetSignissue,
  GetFiledlist,
  GetExamine,
  GetProjectSta,
  DoExamine,
  DoSignissue,
  DoFile,
  TestItemModify,
  GetTestItemInfo,
  SubmittingBack,
  CheckPendingBack,
  ExamineBack,
  SignissueBack,
} from "../../../api/module/user";
import { httpServer } from "../../../api/config";
import { layer } from "@layui/layer-vue";
import { number } from "@intlify/core-base";
import { listToTree } from "../../../library/treeUtil";

export default defineComponent({
  components: {
    mearchMsg,
    layers,
  },
  setup() {
    const fileUploads: any = ref();
    const clickFile = (event: any) => {
      fileUploads.value.dispatchEvent(new MouseEvent("click"));
    };

    const handleImageUpload = (event: any) => {
      const files = event.target.files[0];
      const formData = new FormData();
      formData.append("formFile", files);
      fetch(data.url + "/Checkmsg/CheckPointUpload", {
        method: "POST",
        body: formData,
        headers: {
          token: userInfo.token,
        },
      })
        .then((data: any) => {
          if (data.status == 200) {
            layer.msg("导入成功！", { icon: 1, time: 1000 });
            getSwith();
          }
        })
        .catch((error) => {
          console.error(error);
        });
    };

    const cellStyle = function (row: any, column: any, rowIndex: any, columnIndex: any) {
      let arr = ["entrustmentNo", "sampleNo", "reportNo", "taskNo", "recordNo"];
      // if (row.colors && arr.includes(column.key)) {
      //   return "color:blue";
      // }
      if (row.colors) {
        return "background:#ffff00";
      }
    };

    const selectedKeys: any = ref([]);
    const checkbox = ref(true);

    const user: any = sessionStorage.getItem("userInfo");
    const userInfo: any = JSON.parse(user);

    let httpUrl: any = ref([]);
    const layTab = ref();
    onMounted(() => {
      let url: any = sessionStorage.getItem("httpUrl");
      httpUrl.value = JSON.parse(url);
      getTabItemStep();

      getLastMonth();

      getProjectList();

      getTabItem();

      // if (httpUrl.value.includes("/Checkmsg/GetUnclaims")) {
      //   getList();
      // }
      getProjectSelect();
    });

    const getTabItemStep = () => {
      if (httpUrl.value.includes("/Checkmsg/GetUnclaims")) {
        data.tabs = "1";
      } else if (httpUrl.value.includes("/Checkmsg/GetSubmitting")) {
        data.tabs = "4";
      } else if (httpUrl.value.includes("/Checkmsg/GetCheckPending")) {
        data.tabs = "5";
      } else if (httpUrl.value.includes("/Checkmsg/GetExamine")) {
        data.tabs = "6";
      } else if (httpUrl.value.includes("/Checkmsg/GetSignissue")) {
        data.tabs = "7";
      } else if (httpUrl.value.includes("/Checkmsg/GetFiledlist")) {
        data.tabs = "8";
      }
      console.log("data.tabs", data.tabs);
      getSwith();
    };

    const getProjectSelect = async () => {
      if (httpUrl.value.includes("/Setting/GetTestItemInfo")) {
        const res: any = await GetTestItemInfo({
          pageIndex: 1,
          pagePerCount: 2500,
          condition: "",
        });
        if (res.code == 200) {
          data.selectList = res.data.datas;
        }
      }
    };

    const mainRef = ref();

    const data = reactive({
      url: httpServer,
      httpUrls: httpUrl,
      systemType: sessionStorage.getItem("systemType"),
      itemKey: 0,
      current: 1,
      projectId: null as any,
      total: 0,
      visible: false,
      pages: 0,
      curren: 10,
      limit: 10,
      tabs: "1",
      overDays: 0,
      selectedIds: '',
      centerBox: false,
      msg: '',
      tabDetectionId: 0,
      tuiString: '',
      alterVisible: false,
      showTuiLayu: false,
      tabItem: {
        unclaimsCount: 0,
        unclaims5Count: 0,
        unclaims15Count: 0,
        submittingCount: 0,
        checkPendingCount: 0,
        examineCount: 0,
        signissueCount: 0,
        filedCount: 0,
        submitting5Count: 0,
        submitting10Count: 0,
      } as any,
      dataSource: [] as any,
      selectVal: "" as any,
      selectList: [] as any,
      projectList: [] as any,
      timeData: {
        start: "",
        end: "",
      },
      search: {
        projectName: "",
        entrustmentNo: "",
        sampleNo: "",
        testItems: "",
        reportNo: "",
        client: "",
        manager: '',
        sampleReceivingBTime: null,
        sampleReceivingETime: null,
      } as any,
      headers: {
        token: userInfo.token,
      },
      options: [],
      columns: [
        {
          title: "复选",
          width: "50px",
          type: "checkbox",
          fixed: "left",
        },
        {
          title: "序号",
          width: "60px",
          type: "number",
          fixed: "left",
        },
        {
          title: "检测数量",
          key: "numberofTests",
          width: "100px",
        },
        {
          title: "单位",
          key: "unit",
          width: "80px",
        },
        {
          title: "设备",
          width: "100px",
          customSlot: "deviceName",
          ellipsisTooltip: true,
        },
        {
          title: "检测人员",
          key: "tester",
          width: "100px",
          ellipsisTooltip: true,
        },
        {
          title: "状态",
          customSlot: "status",
          width: "100px",
        },
        {
          title: "结论状态",
          key: "conclusionStatus",
          width: "100px",
        },
        {
          title: "检测项目",
          customSlot: "testItems",
          width: "160px",
          ellipsisTooltip: true,
        },
        {
          title: "委托编号",
          key: "entrustmentNo",
          width: "200px ",
          titleSlot: "no1",
          ellipsisTooltip: true,
        },
        {
          title: "样品编号",
          key: "sampleNo",
          width: "180px",
          titleSlot: "no2",
          ellipsisTooltip: true,
        },
        {
          title: "报告编号",
          key: "reportNo",
          width: "180px",
          titleSlot: "no3",
          ellipsisTooltip: true,
        },
        {
          title: "委托单位",
          key: "client",
          width: "200px",
          ellipsisTooltip: true,
        },
        {
          title: "工程名称",
          key: "projectName",
          width: "200px",
          ellipsisTooltip: true,
        },
        {
          title: "施工部位",
          key: "constructionPosition",
          width: "200px",
          ellipsisTooltip: true,
        },
        {
          title: "委托日期",
          key: "entrustmentDate",
          width: "160px",
          titleSlot: "no4",
          ellipsisTooltip: true,
        },
        {
          title: "规格型号",
          key: "model",
          width: "160px",
          ellipsisTooltip: true,
        },
        {
          title: "收样人",
          key: "sampleReceiver",
          width: "80px",
          ellipsisTooltip: true,
        },
        {
          title: "主检人",
          key: "principalInspector",
          width: "100px",
          ellipsisTooltip: true,
        },
        {
          title: "收费金额",
          key: "chargeAmount",
          width: "80px",
          ellipsisTooltip: true,
        },
        {
          title: "批准日期",
          key: "approvalDate",
          width: "160px",
          ellipsisTooltip: true,
        },
        {
          title: "副检人",
          key: "deputyInspector",
          width: "80px",
          ellipsisTooltip: true,
        },
        {
          title: "检测日期",
          key: "detectionTime",
          width: "160px",
          ellipsisTooltip: true,
        },
        {
          title: "操作",
          fixed: "right",
          width: "80px",
          customSlot: "alter",
        },
      ] as any,
    });

    // GetProjectSta
    const getProjectList = async () => {
      if (httpUrl.value.includes("/Checkmsg/GetProjectSta")) {
        const res: any = await GetProjectSta({
          pageIndex: 1,
          pagePerCount: 1500,
          condition: {},
        });
        if (res.code == 200) {
          data.projectList = res.data.datas;
        }
      }
    };

    const getLastMonth = () => {
      var now = new Date();
      var year = now.getFullYear();
      var month: any = now.getMonth() + 1; //0-11表示1-12月
      var day = now.getDate();
      var dateObj: any = {};
      dateObj.now = year + "-" + month + "-" + day;
      var nowMonthDay = new Date(year, month, 0).getDate(); //当前月的总天数
      if (month - 1 <= 0) {
        //如果是1月，年数往前推一年<br>
        dateObj.last = year - 1 + "-" + 12 + "-" + day;
      } else {
        var lastMonthDay = new Date(year, parseInt(month) - 1, 0).getDate();
        if (lastMonthDay < day) {
          // 1个月前所在月的总天数小于现在的天日期
          if (day < nowMonthDay) {
            //当前天日期小于当前月总天数
            dateObj.last =
              year + "-" + (month - 1) + "-" + (lastMonthDay - (nowMonthDay - day));
          } else {
            dateObj.last = year + "-" + (month - 1) + "-" + lastMonthDay;
          }
        } else {
          dateObj.last = year + "-" + (month - 1) + "-" + day;
        }
      }
      // data.search.sampleReceivingBTime = dateObj.last;
      data.timeData.start = dateObj.last;
      // data.search.sampleReceivingETime = dateObj.now;
      data.timeData.end = dateObj.now;
    };

    const changePrject = () => {
      if (data.projectId) {
        let obj = data.projectList.find((item: any) => {
          return item.detectionId === data.projectId;
        });
        data.search.testItems = obj.testItems;
        getSwith();
      }
    };

    onUnmounted(() => {
      for (const key in data.search) {
        data.search[key] = "";
      }
    });

    const getList = async () => {
      const res = await GetUnclaims({
        pageIndex: data.current,
        pagePerCount: data.limit,
        condition: {
          overDays: data.overDays,
          ...data.search,
        },
      });
      if (res.code === 200) {
        data.total = res.data.totalCount;
        let arr: any = [];
        arr = deWeight(res.data.datas)
        data.dataSource = arr;
        
      }
    };

    const changePage = (item: any) => {
      data.limit = item.limit;
      data.current = item.current;
      getSwith();
    };

    const getTabItem = async () => {
      if (data.httpUrls.includes("/Checkmsg/ObjectStatusCountSta")) {
        const res: any = await ObjectStatusCountSta({});
        if (res.code == 200) {
          data.tabItem = {
            ...res.data,
          };
          data.itemKey++;
        }
      }
    };

    const getSearch = (item: any) => {
      data.search = {
        ...data.search,
        ...item,
      };
      console.log('itemitemitem', item);
      getSwith();
    };

    const headerPx = (item: object) => {
      console.log('8888', item);
      
      data.search = {
        ...data.search,
        ...item,
      };
      getSwith();
    };

    const getSwith = () => {
      console.log("data.tabs", data.tabs);

      switch (data.tabs) {
        case "1":
          data.overDays = 0;
          getList();
          break;
        case "2":
          data.overDays = 5;
          getList();
          break;
        case "3":
          data.overDays = 15;
          getList();
          break;
        case "4":
          GetSubmittingList(0);
          break;
        case "45":
          GetSubmittingList(5);
          break;
        case "410":
          GetSubmittingList(10);

          break;
        case "5":
          GetCheckPendingList();
          break;
        case "6":
          GetExamineList();
          break;
        case "7":
          GetSignissueList();
          break;
        case "8":
          GetFiledlistList();
          break;
      }
      getTabItem();
    };

    const tabChange = () => {
      data.current = 1;
      getSwith();
    };

    const getColumns = (ite: any, tabs: any) => {
      let arr: any = [];
      if (data.systemType == "1") {
        arr = [
          {
            title: "复选",
            width: "50px",
            type: "checkbox",
            fixed: "left",
          },
          {
            title: "序号",
            width: "60px",
            type: "number",
            fixed: "left",
          },
          {
            title: "检测数量",
            key: "numberofTests",
            width: "80px",
          },
          {
            title: "单位",
            key: "unit",
            width: "60px",
            ellipsisTooltip: true,
          },
          {
            title: "设备",
            width: "120px",
            customSlot: "deviceName",
            ellipsisTooltip: true,
          },
          {
            title: "检测人员",
            key: "tester",
            width: "100px",
            ellipsisTooltip: true,
          },
          {
            title: "检测项目",
            customSlot: "testItems",
            width: "160px",
            ellipsisTooltip: true,
          },
          {
            title: "委托编号",
            key: "entrustmentNo",
            width: "200px",
            titleSlot: "no1",
            ellipsisTooltip: true,
          },

          {
            title: "任务编号",
            key: "taskNo",
            width: "180px",
            titleSlot: "no2",
            ellipsisTooltip: true,
          },
          {
            title: "记录编号",
            key: "recordNo",
            width: "180px",
            titleSlot: "no3",
            ellipsisTooltip: true,
          },
          {
            title: "委托日期",
            key: "entrustmentDate",
            width: "160px",
            titleSlot: "no4",
            ellipsisTooltip: true,
          },
          {
            title: "委托完成日期",
            key: "entrustmentFinishDate",
            width: "160px",
            ellipsisTooltip: true,
          },
          {
            title: "委托单位",
            key: "client",
            width: "200px",
            ellipsisTooltip: true,
          },
          {
            title: "工程名称",
            key: "projectName",
            width: "200px",
            ellipsisTooltip: true,
          },
          {
            title: "施工部位/用途",
            key: "constructionPosition",
            width: "200px",
            ellipsisTooltip: true,
          },
          {
            title: "送样数组",
            key: "sampleNumber",
            width: "180px",
            ellipsisTooltip: true,
          },
          {
            title: "样品编号",
            key: "sampleNo",
            width: "180px",
            titleSlot: "no2",
            ellipsisTooltip: true,
          },
          {
            title: "来样数组",
            key: "recieveSampleNo",
            width: "180px",
            ellipsisTooltip: true,
          },
          {
            title: "报告编号",
            key: "reportNo",
            width: "180px",
            titleSlot: "no3",
            ellipsisTooltip: true,
          },
          {
            title: "报告份数",
            key: "reportNumber",
            width: "200px",
            ellipsisTooltip: true,
          },
          {
            title: "试验项目",
            key: "pilotProjects",
            width: "200px",
            ellipsisTooltip: true,
          },
          {
            title: "检测参数",
            key: "detectionParameters",
            width: "200px",
            ellipsisTooltip: true,
          },
          {
            title: "检验类别",
            key: "inspectionCategory",
            width: "200px",
            ellipsisTooltip: true,
          },
          {
            title: "收费状态",
            key: "chargeAmount",
            width: "200px",
            ellipsisTooltip: true,
          },
          {
            title: "主检人",
            key: "principalInspector",
            width: "100px",
            ellipsisTooltip: true,
          },
          {
            title: "报告管理人",
            key: "manager",
            width: "100px",
            ellipsisTooltip: true,
          },
          {
            title: "取样人",
            key: "sampleReceiver",
            width: "100px",
            ellipsisTooltip: true,
          },
          {
            title: "检测结果",
            key: "detectionResult",
            width: "80px",
            ellipsisTooltip: true,
          },
          {
            title: "检测日期",
            key: "detectionTime",
            width: "160px",
            ellipsisTooltip: true,
          },
        ];

        if (tabs > 3) {
          let indexs = arr.findIndex((item: any) => {
            return item.customSlot === "alter";
          });
          if (indexs) {
            arr.splice(indexs, 1);
          }
        } else {
          arr.push({
            title: "操作",
            fixed: "right",
            width: "80px",
            customSlot: "alter",
          });
        }
      } else {
        if (tabs > 3) {
          arr = [
            {
              title: "复选",
              width: "50px",
              type: "checkbox",
              fixed: "left",
            },
            {
              title: "序号",
              width: "60px",
              type: "number",
              fixed: "left",
            },
            {
              title: "检测数量",
              key: "numberofTests",
              width: "80px",
            },
            {
              title: "单位",
              key: "unit",
              width: "60px",
              ellipsisTooltip: true,
            },
            {
              title: "设备",
              width: "120px",
              customSlot: "deviceName",
              ellipsisTooltip: true,
            },
            {
              title: "检测人员",
              key: "tester",
              width: "100px",
              ellipsisTooltip: true,
            },
            {
              title: "报告管理人",
              key: "manager",
              width: "100px",
              ellipsisTooltip: true,
            },
            {
              title: "状态",
              customSlot: "status",
              width: "100px",
              ellipsisTooltip: true,
            },
            {
              title: "结论状态",
              key: "conclusionStatus",
              width: "100px",
              ellipsisTooltip: true,
            },
            {
              title: "检测项目",
              customSlot: "testItems",
              width: "160px",
              ellipsisTooltip: true,
            },
            {
              title: "委托编号",
              key: "entrustmentNo",
              width: "200px",
              titleSlot: "no1",
              ellipsisTooltip: true,
            },
            {
              title: "样品编号",
              key: "sampleNo",
              width: "180px",
              titleSlot: "no2",
              ellipsisTooltip: true,
            },
            {
              title: "报告编号",
              key: "reportNo",
              width: "180px",
              titleSlot: "no3",
              ellipsisTooltip: true,
            },
            {
              title: "委托单位",
              key: "client",
              width: "200px",
              ellipsisTooltip: true,
            },
            {
              title: "工程名称",
              key: "projectName",
              width: "200px",
              ellipsisTooltip: true,
            },
            {
              title: "施工部位",
              key: "constructionPosition",
              width: "200px",
              ellipsisTooltip: true,
            },
            {
              title: "委托日期",
              key: "entrustmentDate",
              width: "160px",
              titleSlot: "no4",
              ellipsisTooltip: true,
            },
            {
              title: "规格型号",
              key: "model",
              width: "160px",
              ellipsisTooltip: true,
            },
            {
              title: "收样人",
              key: "sampleReceiver",
              width: "100px",
              ellipsisTooltip: true,
            },
            {
              title: "主检人",
              key: "principalInspector",
              width: "100px",
              ellipsisTooltip: true,
            },
            {
              title: "收费金额",
              key: "chargeAmount",
              width: "80px",
              ellipsisTooltip: true,
            },
            {
              title: "批准日期",
              key: "approvalDate",
              width: "160px",
              ellipsisTooltip: true,
            },
            {
              title: "副检人",
              key: "deputyInspector",
              width: "80px",
              ellipsisTooltip: true,
            },
            {
              title: "检测日期",
              key: "detectionTime",
              width: "160px",
              ellipsisTooltip: true,
            },
          ];
        } else {
          arr = [...ite];
        }
      }

      return arr;
    };

    const GetExamineList = async () => {
      const res: any = await GetExamine({
        pageIndex: data.current,
        pagePerCount: data.limit,
        condition: {
          ...data.search,
        },
      });
      if (res.code == 200) {
        data.total = res.data.totalCount;
        // data.pages = res.data.pageCount;
        let arr: any = [];
        arr = deWeight(res.data.datas)
        data.dataSource = arr;
      }
    };

    const GetFiledlistList = async () => {
      const res: any = await GetFiledlist({
        pageIndex: data.current,
        pagePerCount: data.limit,
        condition: {
          ...data.search,
        },
      });
      if (res.code == 200) {
        data.total = res.data.totalCount;
        // data.pages = res.data.pageCount;
        let arr: any = [];
        arr = deWeight(res.data.datas)
        data.dataSource = arr;
      }
    };

    const GetSignissueList = async () => {
      const res: any = await GetSignissue({
        pageIndex: data.current,
        pagePerCount: data.limit,
        condition: {
          ...data.search,
        },
      });
      if (res.code == 200) {
        data.total = res.data.totalCount;
        // data.pages = res.data.pageCount;
        // data.dataSource = res.data.datas;
        let arr: any = [];
        arr = deWeight(res.data.datas)
        data.dataSource = arr;
      }
    };

    const GetCheckPendingList = async () => {
      const res: any = await GetCheckPending({
        pageIndex: data.current,
        pagePerCount: data.limit,
        condition: {
          ...data.search,
        },
      });
      if (res.code == 200) {
        data.total = res.data.totalCount;
        // data.pages = res.data.pageCount;
        let arr: any = [];
        arr = deWeight(res.data.datas)
        data.dataSource = arr;
        // data.dataSource = res.data.datas;
      }
    };

    const GetSubmittingList = async (num: Number) => {
      const res: any = await GetSubmitting({
        pageIndex: data.current,
        pagePerCount: data.limit,
        condition: {
          ...data.search,
          overDays: num,
        },
      });
      console.log("res", res);

      if (res.code == 200) {
        data.total = res.data.totalCount;
        // data.pages = res.data.pageCount;
        let arr: any = [];
        arr = deWeight(res.data.datas)
        data.dataSource = arr;
      }
    };

    const layers: any = ref();
    const claimTag = async (item: any) => {
      let arr: any = [];
      if (data.projectList.length) {
        data.projectList.forEach((item: any) => {
          arr.push({
            value: item.detectionId,
            label: item.testItems,
          });
        });
      }
      layers.value.open({
        list: arr,
        tiem: data.timeData,
        detectionId: item.detectionId,
        testItems: item.testItems,
      });
    };

    const allShenghe = async (str?: any) => {
      data.selectedIds = '';
      if (!selectedKeys.value.length)
        return layer.msg("请先选择需要操作的数据", { icon: 3, time: 1000 });
      switch (str) {
        case "dai":
          const res: any = await DoCheckPending({
            objectids: selectedKeys.value.join(","),
          });
          if (res.code == 200) {
            getSwith();
          }
          break;
        case "th":
          const ress: any = await SubmittingBack({
            objectids: selectedKeys.value.join(","),
          });
          if (ress.code == 200) {
            getSwith();
          }
          break;
        case "shenghe":
          const datas: any = await DoExamine({
            objectids: selectedKeys.value.join(","),
          });
          if (datas.code == 200) {
            getSwith();
          }
          break;
        case "dshpl":
          const from: any = await DoExamine({
            objectids: selectedKeys.value.join(","),
          });
          if (from.code == 200) {
            getSwith();
          }
          break;
        case "qianfa":
          const qianfa: any = await DoSignissue({
            objectids: selectedKeys.value.join(","),
          });
          if (qianfa.code == 200) {
            getSwith();
          }
          break;
        case "qftu":
          data.selectedIds = selectedKeys.value.join(",");
          data.showTuiLayu = true;
          // const obj: any = await DoSignissue({
          //   objectids: selectedKeys.value.join(","),
          // });
          // if (obj.code == 200) {
          //   getSwith();
          // }
          break;
        case "guidan":
          const guidan: any = await DoFile({
            objectids: selectedKeys.value.join(","),
          });
          if (guidan.code == 200) {
            getSwith();
          }
          break;
        case "plgdtu":
          data.selectedIds = selectedKeys.value.join(",");
          data.showTuiLayu = true;
          break;
        case "del":
          const del: any = await DelUnclaims({
            objectids: selectedKeys.value.join(","),
          });
          if (del.code == 200) {
            getSwith();
          }
          break;
      }
    };

    const editBtn = [
      {
        text: "确认",
        callback: async () => {
          if (httpUrl.value.includes("/Checkmsg/TestItemModify")) {
            if (data.selectVal) {
              let indexs = data.selectList.findIndex((item: any) => {
                return item.testItemId === data.selectVal;
              });

              const res = await TestItemModify({
                testitem: data.selectList[indexs].testItemName,
                detectionId: data.tabDetectionId,
              });
              if (res.code == 200) {
                data.alterVisible = false;
                getSwith();
              }
            } else {
              layer.msg("请选择项目", { icon: 3, time: 1000 });
            }
          } else {
            layer.msg("您没有修改权限", { icon: 2, time: 1000 });
            data.alterVisible = false;
          }
        },
      },
      {
        text: "取消",
        callback: () => {
          data.alterVisible = false;
        },
      },
    ];

    const tuiBtn = [
      {
        text: "确认",
        callback: async () => {
          if (data.tabs == '6') {
            const res = await ExamineBack({
              objectids: data.selectedIds,
              status: Number(data.tuiString)
            })
            if ( res.code == 200) {
              data.showTuiLayu = false;
              getSwith()
            }
          } else {
             const obj = await SignissueBack({
              objectids: data.selectedIds,
            })
            if ( obj.code == 200) {
              data.showTuiLayu = false;
              getSwith()
            }
          }
        },
      },
      {
        text: "取消",
        callback: () => {
          data.showTuiLayu = false;
        },
      },
    ]

    const addXmName = (row: any) => {
      data.selectVal = null;
      data.tabDetectionId = row.detectionId;
      data.alterVisible = true;
    };

    const deWeight = (arr: any,) => {
      for (let i = 0; i < arr.length - 1; i++) {
        arr[i].colors = false;
        for (let j = i + 1; j < arr.length; j++) {
          if (arr[i].entrustmentNo == arr[j].entrustmentNo) {
            arr[i].colors = true;
            arr[j].colors = true;
          }
        }
      }
      return arr
    }

  
    return {
      tuiBtn,
      allShenghe,
      getSearch,
      claimTag,
      layers,
      editBtn,
      tabChange,
      addXmName,
      mainRef,
      selectedKeys,
      checkbox,
      cellStyle,
      changePage,
      handleImageUpload,
      clickFile,
      fileUploads,
      changePrject,
      getColumns,
      getSwith,
      layTab,
      headerPx,
      ...toRefs(data),
    };
  },
});
</script>

<style scoped>
.tabs .layui-tab-content {
  padding: 0 !important;
}
.workbench .layui-select {
  width: 178px !important;
}

.btn_alter .layui-upload-wrap {
  display: flex !important;
  align-items: center !important;
}
</style>
<style lang="scss" scoped>
.msg_val {
  margin-bottom: 8px;
}

.sdppxm {
  width: 300px;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn_alter {
  display: flex;
  align-items: center;

  .btn {
    margin-left: 20px;
  }
}
.tab_item {
  display: flex;
  align-items: center;
}

.alter_text {
  cursor: pointer;
  .red {
    color: #f71f20;
  }

  .text {
    color: #5453b1;
  }
}
</style>
